/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * This notice applies to any and all portions of this file
  * that are not between comment pairs USER CODE BEGIN and
  * USER CODE END. Other portions of this file, whether 
  * inserted by the user or by software development tools
  * are owned by their respective copyright owners.
  *
  * Copyright (c) 2019 STMicroelectronics International N.V. 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without 
  * modification, are permitted, provided that the following conditions are met:
  *
  * 1. Redistribution of source code must retain the above copyright notice, 
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
  * 3. Neither the name of STMicroelectronics nor the names of other 
  *    contributors to this software may be used to endorse or promote products 
  *    derived from this software without specific written permission.
  * 4. This software, including modifications and/or derivative works of this 
  *    software, must execute solely and exclusively on microcontroller or
  *    microprocessor devices manufactured by or for STMicroelectronics.
  * 5. Redistribution and use of this software other than as permitted under 
  *    this license is void and will automatically terminate your rights under 
  *    this license. 
  *
  * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
  * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
  * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
  * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

#include	"LwipServer_Task.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */     

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
osThreadId defaultTaskHandle;
osThreadId Config_TaskHandle;
osThreadId MC_TCP_TaskHandle;
osThreadId Modbus_Server_THandle;
osThreadId FX_RX_TaskHandle;

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
   
/* USER CODE END FunctionPrototypes */

void StartDefaultTask(void const * argument);
void ConfigTask(void const * argument);
void MCTCPTask(void const * argument);
void ModbusServerTask(void const * argument);
void FXRXTask(void const * argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */
       
  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityLow, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

    StartLwipServerTask();
  /* definition and creation of Config_Task */
  //osThreadDef(Config_Task, ConfigTask, osPriorityIdle, 0, 256);
  //Config_TaskHandle = osThreadCreate(osThread(Config_Task), NULL);

  /* definition and creation of MC_TCP_Task */
  //osThreadDef(MC_TCP_Task, MCTCPTask, osPriorityIdle, 0, 256);
  //MC_TCP_TaskHandle = osThreadCreate(osThread(MC_TCP_Task), NULL);

  /* definition and creation of Modbus_Server_T */
  //osThreadDef(Modbus_Server_T, ModbusServerTask, osPriorityIdle, 0, 256);
  //Modbus_Server_THandle = osThreadCreate(osThread(Modbus_Server_T), NULL);

  /* definition and creation of FX_RX_Task */
  //osThreadDef(FX_RX_Task, FXRXTask, osPriorityIdle, 0, 256);
  //FX_RX_TaskHandle = osThreadCreate(osThread(FX_RX_Task), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */
}

/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used 
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
char buf[1024];
void StartDefaultTask(void const * argument)
{

  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  for(;;)
  {
      //vTaskList(buf);
      //printf(buf);
		HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);
    osDelay(500);
		HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET);
		osDelay(500);
  }
  /* USER CODE END StartDefaultTask */
}

/* USER CODE BEGIN Header_ConfigTask */
/**
* @brief Function implementing the Config_Task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_ConfigTask */
void ConfigTask(void const * argument)
{
  /* USER CODE BEGIN ConfigTask */
	printf("ConfigTask\n");
  /* Infinite loop */
  for(;;)
  {
		HAL_GPIO_WritePin(RX1_LED_GPIO_Port, RX1_LED_Pin, GPIO_PIN_SET);
    osDelay(1000);
		HAL_GPIO_WritePin(RX1_LED_GPIO_Port, RX1_LED_Pin, GPIO_PIN_RESET);
    osDelay(1000);
  }
  /* USER CODE END ConfigTask */
}

/* USER CODE BEGIN Header_MCTCPTask */
/**
* @brief Function implementing the MC_TCP_Task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_MCTCPTask */
void MCTCPTask(void const * argument)
{
  /* USER CODE BEGIN MCTCPTask */
	printf("MCTCPTask\n");
  /* Infinite loop */
  for(;;)
  {
    HAL_GPIO_WritePin(GPIOD, RX3_LED_Pin, GPIO_PIN_RESET);
    osDelay(1000);
		HAL_GPIO_WritePin(GPIOD, RX3_LED_Pin, GPIO_PIN_SET);
    osDelay(1000);
  }
  /* USER CODE END MCTCPTask */
}

/* USER CODE BEGIN Header_ModbusServerTask */
/**
* @brief Function implementing the Modbus_Server_T thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_ModbusServerTask */
void ModbusServerTask(void const * argument)
{
  /* USER CODE BEGIN ModbusServerTask */
	printf("ModbusServerTask\n");
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END ModbusServerTask */
}

/* USER CODE BEGIN Header_FXRXTask */
/**
* @brief Function implementing the FX_RX_Task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_FXRXTask */
void FXRXTask(void const * argument)
{
  /* USER CODE BEGIN FXRXTask */
	printf("FXRXTask\n");
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END FXRXTask */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
     
/* USER CODE END Application */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
